﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AgileZen.Models;

namespace AgileZen.Sample.Controllers
{
    public class CommentController : AgileZenController
    {
        //
        // GET: /Comment/

        public ActionResult Index(int projectid, int storyid)
        {
            return View(AgileZenService.GetComments(projectid, storyid));
        }

        public ActionResult Add(int projectid, int storyid)
        {
            return View();
        }

        [HttpPost]
        public ActionResult Add(int projectid, int storyid, Comment comment)
        {
            try
            {
                AgileZenService.CreateComment(projectid,storyid, ref comment);

                return RedirectToAction("Index", new { storyid = storyid, projectid = projectid });
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Project/Edit/5

        public ActionResult Edit(int projectid, int storyid, int id)
        {

            try
            {
                var tag = AgileZenService.GetComment(projectid,storyid, id);
                return View(tag);
            }
            catch
            {
                return View();
            }

        }

        //
        // POST: /Project/Edit/5

        [HttpPost]
        public ActionResult Edit(int projectid, int storyid, Comment comment)
        {
            try
            {
                // TODO: Add update logic here
                AgileZenService.UpdateComment(projectid, storyid, ref comment);
                return RedirectToAction("Index", new { projectid = projectid, storyid = storyid });
            }
            catch
            {
                return View();
            }
        }



        public ActionResult Delete(int projectid, int storyid ,int id)
        {
            try
            {
                AgileZenService.DeleteComment(projectid,storyid, id);

                return RedirectToAction("Index", new { projectid = projectid, storyid = storyid });
            }
            catch
            {
                return View();
            }
        }
    }
}
